package Dialog;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class JoinDialog extends GobangDialog {
    public static int confirm = 1;
    public static int cancel = 0;
    private JButton confirmButton, cancelButton;
    private JTextField textField;

    /**
     * Dialog的构造函数
     *
     * @param jFrame
     * @param title  对话框标题
     * @param b
     */
    public JoinDialog(JFrame jFrame, String title, boolean b) {
        super(jFrame, title, b);
        this.init();
    }

    /**
     * 初始化加入房间对话框
     *
     * <p>初始化内容包括选项与内容</p>
     */
    private void init() {
        confirmButton = new JButton("加入房间");
        cancelButton = new JButton("取  消");
        textField = new JTextField();

        this.setButtonStyle1(confirmButton);
        this.setButtonStyle2(cancelButton);

        textField.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
        textField.setBounds(50, 40, 180, 30);
        textField.setText("请输入对方IP地址");
        textField.addActionListener(this);

        add(confirmButton);
        add(cancelButton);
        add(textField);
    }

    /**
     * 获取IP地址输入框实例
     *
     * @return IP地址输入框
     */
    public JTextField getTextField() {
        return textField;
    }

    /**
     * 通过用户点击的按键来相应不同的事件
     *
     * <p>当用户点击重新开始时重新开始一局游戏
     * 当用户点击返回时返回初始菜单</p>
     *
     * @param e 用户点击的按键
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == cancelButton) {
            message = cancel;
            setVisible(false);
        } else if (e.getSource() == confirmButton) {
            message = confirm;
            setVisible(false);
        }
    }

}
